﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Space_Conquest
{

    [Serializable]
    class SequenceWrapper :  IComparable
    {

        public object Object;
        public int Sequence;
    
        #region IComparable Members

        public int  CompareTo(object obj)
        {
            SequenceWrapper other = (SequenceWrapper)obj;
 	        return this.Sequence.CompareTo(other.Sequence);
        }

        #endregion

    }

    /// <summary>
    /// Same as Server, but insures client sending to gets messages in correct order
    /// </summary>
    class SequentialServer : Server
    {

        public int sequenceOrder = 0;

        public SequentialServer() :
            base()
        {
        }

        public SequentialServer(int portNumber) :
            base(portNumber)
        {

        }

        public override void SendData(object obj)
        {

            SequenceWrapper wrapper = new SequenceWrapper();
            wrapper.Sequence = sequenceOrder++;
            wrapper.Object = obj;

            base.SendData(wrapper);

        }

        public override void SendData(object obj, int clientIndex)
        {

            SequenceWrapper wrapper = new SequenceWrapper();
            wrapper.Sequence = sequenceOrder++;
            wrapper.Object = obj;

            base.SendData(wrapper, clientIndex);

        }

    }

}
